home *** CD-ROM | disk | FTP | other *** search
/ Champak 50 / Volume 50 - JOGO DISK .iso / Games / moonstonemadness.swf / scripts / __Packages / SideScroller / SideScrollerManager.as < prev    next >
Encoding:
Text File  |  2007-09-27  |  5.4 KB  |  190 lines

  1. class SideScroller.SideScrollerManager extends Library.DispatcherBase
  2. {
  3.    var mcRef;
  4.    var oParentObject;
  5.    var aLayers;
  6.    var nCurrentPosition;
  7.    var bAutoScroll;
  8.    var nNextDepth;
  9.    var nStageWidth;
  10.    var nStageHeight;
  11.    var oCamera;
  12.    var nScrollSpeed;
  13.    var nScrollMethod;
  14.    var oDefaultLayerId;
  15.    var bPaused;
  16.    static var _oCtrl;
  17.    static var LOOP_BUFFER = 150;
  18.    static var SCROLL_ONE_WAY = 1;
  19.    static var SCROLL_BOTH_SIDE = 2;
  20.    static var ONE_WAY_CAMERA_BUFFER = 120;
  21.    function SideScrollerManager(__mcRef, __nStageWidth, __nStageHeight, __oParentObject)
  22.    {
  23.       super();
  24.       this.mcRef = __mcRef;
  25.       this.oParentObject = __oParentObject;
  26.       SideScroller.Ground.doClean();
  27.       SideScroller.SideScrollerManager._oCtrl = this;
  28.       this.aLayers = new Array();
  29.       this.nCurrentPosition = 0;
  30.       this.bAutoScroll = false;
  31.       this.nNextDepth = 0;
  32.       this.nStageWidth = __nStageWidth;
  33.       this.nStageHeight = __nStageHeight;
  34.       this.oCamera = new SideScroller.BasicCamera(this.nStageWidth,this.nStageHeight,this);
  35.       this.oParentObject.doAddListener(this);
  36.    }
  37.    static function get Instance()
  38.    {
  39.       return SideScroller.SideScrollerManager._oCtrl;
  40.    }
  41.    function doEnterFrame()
  42.    {
  43.       super.doEnterFrame();
  44.       this.doMoveLayers();
  45.    }
  46.    function doAddLayer(__oLayerID, __nLayerType, __nAttachMethod)
  47.    {
  48.       var _loc3_ = this.mcRef.createEmptyMovieClip(__oLayerID.toString() + "_" + this.nNextDepth,this.nNextDepth);
  49.       var _loc2_ = new SideScroller.Layer(__oLayerID,_loc3_,__nLayerType,__nAttachMethod,this);
  50.       this.aLayers.push(_loc2_);
  51.       this.nNextDepth = this.nNextDepth + 1;
  52.       return _loc2_;
  53.    }
  54.    function setScrollSpeed(__nScrollSpeed)
  55.    {
  56.       this.nScrollSpeed = __nScrollSpeed;
  57.    }
  58.    function setScrollMethod(__nScrollMethod)
  59.    {
  60.       this.nScrollMethod = __nScrollMethod;
  61.    }
  62.    function setDefaultLayer(__oLayerID)
  63.    {
  64.       this.oDefaultLayerId = __oLayerID;
  65.    }
  66.    function getLayer(__oLayerID)
  67.    {
  68.       var _loc3_ = undefined;
  69.       var _loc2_ = undefined;
  70.       _loc2_ = 0;
  71.       while(_loc2_ <= this.aLayers.length - 1)
  72.       {
  73.          if(this.aLayers[_loc2_].Id == __oLayerID)
  74.          {
  75.             _loc3_ = this.aLayers[_loc2_];
  76.          }
  77.          _loc2_ = _loc2_ + 1;
  78.       }
  79.       return _loc3_;
  80.    }
  81.    function getLayerFor(__mcObject)
  82.    {
  83.       var _loc3_ = undefined;
  84.       var _loc2_ = undefined;
  85.       _loc2_ = 0;
  86.       while(_loc2_ <= this.aLayers.length - 1)
  87.       {
  88.          if(String(__mcObject).indexOf(String(this.aLayers[_loc2_].Ref)) != -1)
  89.          {
  90.             _loc3_ = this.aLayers[_loc2_];
  91.          }
  92.          _loc2_ = _loc2_ + 1;
  93.       }
  94.       return _loc3_;
  95.    }
  96.    function doAddStaticObject(__mcObject)
  97.    {
  98.       var _loc2_ = this.getLayerFor(__mcObject);
  99.       var _loc3_ = new SideScroller.StaticObject(__mcObject,_loc2_);
  100.    }
  101.    function doDestroy()
  102.    {
  103.       this.oParentObject.doRemoveListener(this);
  104.       this.oCamera.doDestroy();
  105.       delete this.oCamera;
  106.       delete SideScroller.SideScrollerManager._oCtrl;
  107.       delete this.oParentObject;
  108.       for(var _loc3_ in this.aLayers)
  109.       {
  110.          this.aLayers[_loc3_].doDestroy();
  111.       }
  112.       super.doDestroy();
  113.    }
  114.    function get Active()
  115.    {
  116.       return !this.bPaused;
  117.    }
  118.    function get StageWidth()
  119.    {
  120.       return this.nStageWidth;
  121.    }
  122.    function get StageHeight()
  123.    {
  124.       return this.nStageHeight;
  125.    }
  126.    function get ScrollMethod()
  127.    {
  128.       return this.nScrollMethod;
  129.    }
  130.    function get CameraManager()
  131.    {
  132.       return this.oCamera;
  133.    }
  134.    function get Limits()
  135.    {
  136.       var _loc4_ = new Object();
  137.       var _loc3_ = undefined;
  138.       var _loc2_ = undefined;
  139.       _loc2_ = 0;
  140.       while(_loc2_ <= this.aLayers.length - 1)
  141.       {
  142.          if(this.aLayers[_loc2_].Id == this.oDefaultLayerId)
  143.          {
  144.             _loc3_ = this.aLayers[_loc2_];
  145.          }
  146.          _loc2_ = _loc2_ + 1;
  147.       }
  148.       _loc4_.left = 0;
  149.       _loc4_.right = _loc3_.PanelsWidth;
  150.       _loc4_.top = 0;
  151.       _loc4_.bottom = _loc3_.PanelsHeight;
  152.       return _loc4_;
  153.    }
  154.    function doMoveLayers()
  155.    {
  156.       var _loc2_ = undefined;
  157.       _loc2_ = 0;
  158.       while(_loc2_ <= this.aLayers.length - 1)
  159.       {
  160.          if(this.nScrollMethod == SideScroller.SideScrollerManager.SCROLL_ONE_WAY)
  161.          {
  162.             var _loc3_ = this.nCurrentPosition;
  163.             this.nCurrentPosition = Math.min(this.nCurrentPosition,this.oCamera.PosX);
  164.             if(this.nCurrentPosition < this.oCamera.PosX - SideScroller.SideScrollerManager.ONE_WAY_CAMERA_BUFFER)
  165.             {
  166.                this.nCurrentPosition = this.oCamera.PosX - SideScroller.SideScrollerManager.ONE_WAY_CAMERA_BUFFER;
  167.             }
  168.             else if(this.bAutoScroll)
  169.             {
  170.                this.nCurrentPosition -= this.nScrollSpeed;
  171.             }
  172.             if(this.nCurrentPosition < - (this.Limits.right - this.nStageWidth))
  173.             {
  174.                this.nCurrentPosition = - (this.Limits.right - this.nStageWidth);
  175.             }
  176.             if(this.nCurrentPosition > _loc3_)
  177.             {
  178.                this.nCurrentPosition = _loc3_;
  179.             }
  180.          }
  181.          else
  182.          {
  183.             this.nCurrentPosition = this.oCamera.PosX;
  184.          }
  185.          this.aLayers[_loc2_].doMoveTo(this.nCurrentPosition,this.oCamera.PosY);
  186.          _loc2_ = _loc2_ + 1;
  187.       }
  188.    }
  189. }
  190.